﻿using System;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;
using System.Linq.Dynamic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using PortalWeb.Business.Entity;

namespace PortalWeb.Business.Manager
{
    public class ApplicationRoleManager : RoleManager<ApplicationRoleModel>, IDisposable
    {
        public ApplicationRoleManager(IRoleStore<ApplicationRoleModel, string> store)
            : base(store)
        {
          
        }

        public static ApplicationRoleManager Create()
        {
            return new ApplicationRoleManager(new RoleStore<ApplicationRoleModel>());
        }

        public virtual int Count()
        {
            return Roles.Count();
        }

        [DebuggerStepThrough]
        public virtual async Task<ApplicationRoleModel[]> LoadPageEntitiesnAsync<TS>(
            Expression<Func<ApplicationRoleModel, bool>> whereLambda, string order, string sort, int offset, int limit)
        {
            this.ThrowIfDisposed();
            return await Roles.Where(whereLambda)
                .OrderBy(sort + " " + order).Skip(offset)
                .Take(limit - offset)
                .ToArrayAsync();
        }



        private void ThrowIfDisposed()
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(base.GetType().Name);
            }
        }

        private bool _disposed;

        public new void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

       
    }
}
